﻿using _02;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jiance
{
    public partial class Form3 : Form
    {
        DBHelper db = new DBHelper();
        DataSet ds = new DataSet();
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            string sql1 = "select StationID,InputName,StartDate,EndDate,PM,whi,Notes from AirQualityInfo";
            SqlDataAdapter m = new SqlDataAdapter(sql1, db.Connection);
            m.Fill(ds, "AirQualityInfo");
            this.dataGridView1.DataSource = ds.Tables["AirQualityInfo"];
            db.CloseConnection();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请输入查询条件");
            }
            else
            {
                
                db.OpenConnection();
                string sql = "select StationID,InputName,StartDate,EndDate,PM,whi,Notes from AirQualityInfo where InputName like N'%" + this.textBox1.Text + "%'";
                SqlCommand com = new SqlCommand(sql, db.Connection);
                SqlDataReader read = com.ExecuteReader();
                while (!read.HasRows)
                {
                    MessageBox.Show("没有该内容");
                    this.textBox1.Text = null;
                    read.Close();
                    db.CloseConnection();
                    return;
                }
                read.Close();


                SqlDataAdapter m = new SqlDataAdapter(sql, db.Connection);
                m.Fill(ds, "ScheduleInfo");
                this.dataGridView1.DataSource = ds.Tables["ScheduleInfo"];
                db.CloseConnection();

            }
        }
    }
}
